import { request } from "../../request/index.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
import { login } from "../../utils/asyncWx.js";

Page({
    async getUserProfile(e) {
        wx.getUserProfile({
            desc: '获取用户资料',
            success: (async (res) => {
                wx.setStorageSync("userinfo", res.userInfo);
                const { encryptedData, rawData, iv, signature } = res;
                const { code } = await login();
                const loginParams = { encryptedData, rawData, iv, signature, code };
                const { token } = await request({ url: "/auth/login", data: loginParams, method: "post" });
                // 4 把token存入缓存中 同时跳转回上一个页面
                if(token){
                    wx.setStorageSync("token", token);
                }
                wx.navigateBack({
                    delta: 1
                });
            })
        })
    }
})